package com.pos.dao.impl;

import com.pos.HibernateUtil;
import com.pos.dao.UsersDAO;
import com.pos.pojo.Users;
import org.hibernate.Hibernate;
import org.hibernate.Session;


import org.hibernate.query.Query;
import org.springframework.orm.hibernate5.HibernateTemplate;

import java.util.List;

public class UsersDAOImpl extends HibernateTemplate implements UsersDAO {


    @Override
    public String getPassword(String userid) {
        Users users = getUserById(userid);
        return users.getPassword();
    }

    @Override
    public Users getUserById(String userId) {
        System.out.println(userId);
        List<Users> users = (List<Users>) find("from com.pos.pojo.Users");
        for(Users u:users){
            if(u.getUserId().equals(userId))
                return u;
        }
        return null;
    }

    @Override
    public List<Users> list() {
        return (List<Users>) find("from com.pos.pojo.Users ");
    }

    @Override
    public void add(Users users) {
        save(users);
    }

    @Override
    public void delete(int userID) {
        super.delete(userID);
    }

    @Override
    public Users get(int userID) {
        return (Users) get(Users.class,userID);
    }

    @Override
    public void update(Users users) {
        super.update(users);
    }
}
